home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #3 / Amiga Plus CD - 2002 - No. 03.iso / AmiSoft / Util / Misc / Lottery2002.lha / Lottery2002 / Source / gui.c < prev    next >
C/C++ Source or Header  |  2002-11-26  |  4KB  |  176 lines

  1. /* gui.c */
  2.  
  3. #include "includes.h"
  4. #include "externals.h"
  5.  
  6. BOOL opengui()
  7. {
  8.     struct TextAttr helvetica= {"helvetica.font", 24, FS_NORMAL, FPF_DISKFONT};
  9.     struct MsgPort  *AppPort;
  10.     struct Window   *win;
  11.     struct Gadget   *gadgets[GAD_LAST];
  12.     struct DiskObject *diskobj;
  13.     Object          *object;
  14.     
  15.     if(diskobj = GetDiskObject("PROGDIR:Lottery2002"));
  16.     {
  17.         diskobj->do_CurrentX = NO_ICON_POSITION;
  18.         diskobj->do_CurrentY = NO_ICON_POSITION;
  19.     }
  20.  
  21.     if(!(setmenus())) return(TRUE);
  22.  
  23.     if (!(AppPort = CreateMsgPort()))
  24.     {
  25.         FreeMenus(g_menustrip);
  26.         requester(g_title,
  27.                    "Could not open Message Port.", g_button);
  28.         return(TRUE);
  29.     }
  30.  
  31.     /* Create the Window object & attach the menus & buttons */
  32.     object = WindowObject,
  33.         WA_ScreenTitle, g_scrtitle,
  34.         WA_Title,        "Lottery2002 © T.Collier",
  35.         WA_Activate,     TRUE,
  36.         WA_DepthGadget,  TRUE,
  37.         WA_DragBar,      TRUE,
  38.         WA_CloseGadget,  TRUE,
  39.         WA_SizeGadget,   TRUE,
  40.  
  41.         WINDOW_GadgetHelp,    TRUE,
  42.         WINDOW_MenuStrip,     g_menustrip,
  43.         WINDOW_IconifyGadget, TRUE,
  44.         WINDOW_Icon,          diskobj,//GetDiskObject("PROGDIR:Lottery2002"),
  45.         WINDOW_IconTitle,     "Lottery2002",
  46.         WINDOW_AppPort,       AppPort,
  47.         WINDOW_Position,      WPOS_CENTERSCREEN,
  48.         WINDOW_ParentGroup,   gadgets[GAD_FIRST] = VGroupObject,
  49.  
  50.             LAYOUT_SpaceOuter,    TRUE,
  51.             LAYOUT_DeferLayout,   TRUE,
  52.             
  53.             StartHGroup,
  54.                 Offset(INTERSPACE,INTERSPACE/2,INTERSPACE,INTERSPACE),
  55.                 LAYOUT_BevelStyle,    BVS_GROUP,
  56.                 LAYOUT_Label,            "Your Lottery Numbers For Wednesday",
  57.                 LOTTO_Box(GAD_BOX1),
  58.                 LOTTO_Box(GAD_BOX2),
  59.                 LOTTO_Box(GAD_BOX3),    // My macros, defined in includes.h
  60.                 LOTTO_Box(GAD_BOX4),
  61.                 LOTTO_Box(GAD_BOX5),
  62.                 LOTTO_Box(GAD_BOX6),
  63.             EndHGroup,
  64.             CHILD_WeightedHeight, 0,
  65.  
  66.             StartHGroup,
  67.                 Offset(INTERSPACE,INTERSPACE/2,INTERSPACE,INTERSPACE),
  68.                 LAYOUT_BevelStyle,    BVS_GROUP,
  69.                 LAYOUT_Label,            "Your Lottery Numbers For Saturday",
  70.                 LOTTO_Box(GAD_BOX7),
  71.                 LOTTO_Box(GAD_BOX8),
  72.                 LOTTO_Box(GAD_BOX9),    // My macros, defined in includes.h
  73.                 LOTTO_Box(GAD_BOX10),
  74.                 LOTTO_Box(GAD_BOX11),
  75.                 LOTTO_Box(GAD_BOX12),
  76.             EndHGroup,
  77.             CHILD_WeightedHeight, 0,
  78.             
  79.             StartHGroup,
  80.                 StartMyFuelGauge(GAD_FUEL, 235, FALSE), // MyFuelGauge macro defined in includes.h
  81.             EndHGroup,
  82.             CHILD_WeightedHeight, 0,
  83.  
  84.             StartHGroup,    // StartMyButton is my macro, defined in includes.h
  85.                 StartMyButton(GAD_START, "_Start", FALSE),
  86.                 BUTTON_SoftStyle, FSF_BOLD,
  87.                 ButtonEnd,
  88.                 
  89.                 StartMyButton(GAD_SPEAK, "Sp_eak", spk_flag ^ 1),
  90.                 ButtonEnd,
  91.  
  92.                 StartMyButton(GAD_QUIT, "_Quit", FALSE),
  93.                 ButtonEnd,
  94.             EndHGroup,
  95.             CHILD_WeightedHeight, 0,
  96.         EndGroup,
  97.     EndWindow;
  98.     
  99.     if (!(object)) // Did we get the object created ?
  100.     {
  101.         requester(g_title,
  102.                    "Could not create Window Object.", g_button);
  103.  
  104.         ClearMenuStrip(win);
  105.         FreeMenus(g_menustrip);
  106.         DeleteMsgPort(AppPort);
  107.         return(TRUE);
  108.     }
  109.     
  110.     if(win = (struct Window *) RA_OpenWindow(object))
  111.     {
  112.         get_num(win, gadgets);
  113.         events(AppPort, object, gadgets, win);
  114.     }
  115.     else
  116.     {
  117.         requester(g_title,
  118.                    "Could not open Window.", g_button);
  119.     }
  120.     FreeMenus(g_menustrip);
  121.     DeleteMsgPort(AppPort);
  122.     DisposeObject(object);
  123.     return(TRUE); 
  124. }
  125.  
  126. /* I have used the Menu Macros defined in "reaction_macros.h"       **
  127. ** except for the Speak menu item as I need access to the nm_flags, **
  128. ** in order to disable it if no narrator.device was found in DEVS:  */
  129. BOOL setmenus(void)
  130. {
  131.     BOOL flag = TRUE;
  132.     void             *vi  = NULL;
  133.     struct Screen    *scr = NULL;
  134.     struct NewMenu mymenu[] =
  135.     {
  136.        Title("Project"),
  137.             Item("Start",   "S",0),
  138.             {NM_ITEM, "Speak", "E",spk_flag > 0 ? 0 : NM_ITEMDISABLED, 0, 0,},
  139.             ItemBar,
  140.             Item("About...","A",0),
  141.             Item("Iconify", "I",0),
  142.             ItemBar,
  143.             Item("Quit",    "Q",0),
  144.        EndMenu,
  145.     };
  146.     
  147.     if (scr = LockPubScreen(NULL))
  148.     {
  149.         if (vi = GetVisualInfo(scr, TAG_END))
  150.         {
  151.             if(g_menustrip = CreateMenus(mymenu, TAG_END))
  152.             {
  153.                 if(LayoutMenus(g_menustrip, vi, GTMN_NewLookMenus, TRUE,TAG_END))
  154.                 {
  155.                     ; // Do nothing! 
  156.                 }
  157.                 else
  158.                     flag =requester(g_title, "Could NOT LAYOUT Menus.", g_button);
  159.  
  160.             }
  161.             else
  162.                 flag = requester(g_title, "Could NOT CREATE Menus.", g_button);
  163.  
  164.         FreeVisualInfo(vi);
  165.         }
  166.         else
  167.             flag = requester(g_title, "Could NOT GET\nScreen Visual Info", g_button);
  168.  
  169.     UnlockPubScreen(NULL, scr);
  170.     }
  171.     else
  172.         flag = requester(g_title, "Could NOT LOCK\nDefault Public Screen", g_button);
  173.  
  174.     return(flag);
  175. }
  176.